//
//  ST_DTInviteVoiceGroupCell.swift
//  ST_DTInviteVoiceGroupCell
//
//  Created by Jason on 2021/8/25.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import SwiftyAttributes

class ST_DTInviteVoiceGroupCell: ST_DTChatCell {
    
    override func commonInit() {
        super.commonInit()
    }
    
    static let height = (170+15).cgFloat
    
    fileprivate lazy var box_view:UIView = {
        let control = UIView()
        control.backgroundColor = .white
        control.borderColor = UIColor.init(hexString: "#F5F8FA")
        control.borderWidth = 1
        control.cornerRadius = 10
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(click_goods))
        
        control.addGestureRecognizer(tap)
        
        return control
    }()
    
    var join_closure:((ST_BTIMInviteMessageModel)->())?
    
    @objc fileprivate func click_goods(){
        
        guard let m = message.inviteVoiceRoom else{
            return
        }
        
        join_closure?(m)
    }
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = .scaleAspectFill
        control.cornerRadius = 6
        return control
    }()
    
    fileprivate lazy var invite_title_label:UILabel = {
        let l = UILabel()
        l.textColor = UIColor(hexString: "#333333")
        l.font = .systemFont(ofSize: 14, weight: .medium)
        l.text = "邀请你来一起聊天"
        return l
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let l = UILabel()
        l.textColor = UIColor(hexString: "#ACB4C0")
        l.font = .systemFont(ofSize: 12, weight: .regular)
        return l
    }()
    
    fileprivate lazy var accept_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = #colorLiteral(red: 0.9960784314, green: 0.7607843137, blue: 0.02745098039, alpha: 1)
        control.cornerRadius = 34/2.0
        control.setTitleForAllStates("立即加入")
        control.setTitleColorForAllStates(UIColor.white)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)
        control.isUserInteractionEnabled = false
        return control
    }()
    
    
    
    override var message: ST_DTChatMessage!{
        didSet{
            
            if uuid == message.uuid{
                return
            }
            
            
            self.uuid = message.uuid
            
            icon.sd_setImage(with: message.portraitUri.compress_image().url,for: UIControl.State.normal, completed: nil)
            
            guard let invite = message.inviteVoiceRoom else { return  }
            
            cover_image_view.pin_setImage(from: invite.avatar.url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
            content_label.text = invite.nickname + "的派对"
            
        }
    }
}




//MARK: - Left


class ST_DTInviteVoiceGroupLeftCell: ST_DTInviteVoiceGroupCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func commonInit() {
        super.commonInit()
        
        icon.snp.makeConstraints { (make) in
            make.width.height.equalTo(DTChatUserImageWidth)
            make.left.top.equalToSuperview().offset(15)
        }
        
        contentView.addSubview(box_view)
        box_view.snp.makeConstraints { (make) in
            make.width.equalTo(170)
            make.height.equalTo(170)
            make.left.equalTo(icon.snp.right).offset(4)
            make.top.equalTo(icon)
        }
        
        box_view.addSubview(invite_title_label)
        invite_title_label.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(12)
            make.height.equalTo(20)
        }
        
        box_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(42)
            make.height.width.equalTo(40)
        }
        
        box_view.addSubview(content_label)
        content_label.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(94)
            make.height.equalTo(17)
        }
        
        box_view.addSubview(accept_btn)
        accept_btn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-15)
            make.right.equalToSuperview().offset(-25)
            make.left.equalToSuperview().offset(25)
            make.height.equalTo(34)
        }
        
        
    }
}


//MARK: - Right
class ST_DTInviteVoiceGroupRightCell: ST_DTInviteVoiceGroupCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func commonInit() {
        super.commonInit()
        
        contentView.addSubview(box_view)
        box_view.snp.makeConstraints { (make) in
            make.width.equalTo(170)
            make.height.equalTo(170)
            make.right.equalToSuperview().offset(-15)
            make.top.equalToSuperview().offset(15)
        }
        
        box_view.addSubview(invite_title_label)
        invite_title_label.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(12)
            make.height.equalTo(20)
        }
        
        box_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(42)
            make.height.width.equalTo(40)
        }
        
        box_view.addSubview(content_label)
        content_label.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(94)
            make.height.equalTo(17)
        }
        
        box_view.addSubview(accept_btn)
        accept_btn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-15)
            make.right.equalToSuperview().offset(-25)
            make.left.equalToSuperview().offset(25)
            make.height.equalTo(34)
        }
    }
    
}
